// routes/unifiedAsr.js
// 统一ASR路由

const express = require('express');
const router = express.Router();
const multer = require('multer');

// 引入认证中间件
const auth = require('../middleware/auth');

// 引入控制器
const { unifiedTranscribe } = require('../controllers/unifiedAsrController');

// 引入日志工具
const logger = require('../utils/logger');

// 配置multer用于处理音频文件上传
const storage = multer.memoryStorage();
const upload = multer({ 
    storage: storage,
    limits: {
        fileSize: 10 * 1024 * 1024, // 限制文件大小为10MB
    },
    fileFilter: (req, file, cb) => {
        // 只接受音频文件
        if (file.mimetype.startsWith('audio/')) {
            cb(null, true);
        } else {
            logger.warn('AUDIO_UPLOAD', 'Invalid file type uploaded', { mimetype: file.mimetype });
            cb(new Error('Only audio files are allowed'), false);
        }
    }
});

// @route   POST /api/unified-asr/transcribe
// @desc    使用统一ASR服务转录音频
// @access  Private (需要登录)
router.post('/transcribe', auth, upload.single('audio'), unifiedTranscribe);

// @route   POST /api/unified-asr/transcribe-public
// @desc    使用统一ASR服务转录音频（公开接口，无需认证）
// @access  Public
router.post('/transcribe-public', upload.single('audio'), unifiedTranscribe);

module.exports = router;